﻿//
//  Map_Settlements
//  Trukkr
//
//  Created by Mathew Purchase 2014.
//  Copyright (c) 2014 Pariah Air. All rights reserved.
//

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class Map_Settlements : MonoBehaviour {


	//---------------------------------------------------------------------------------------------
	// Properties
	public float SettlementCash;
	public float Population;
	public float TempDistance = 100;
	public int Settlement_ID;
	
	public float foodPrice = 3;
	public float waterPrice = 7;
	public float hoochPrice = 18;
	public float partsPrice = 35;
	
	public float foodVariation;
	public float waterVariation;
	public float hoochVariation;
	public float partsVariation;
	
	public int Destination;
	public float distance;
	public int CurrentSettlement;
	
	//---------------------------------------------------------------------------------------------
	// Members 
	
	public List<GameObject> ConnectedTowns;
	
	
	public string SettlementName;
	
	public Text SettlementNameText;
	public Text PopupText;
	public Text PopupDistance;
	
	public MapPanel Panel;
	public SetActiveSettlement GoButton;
	public SettlementService SettlementMain;

	public GameObject obj_CurrentSettlement;
	public GameObject obj_DestinationSettlement;
	
	
	//---------------------------------------------------------------------------------------------
	// init
	void OnEnable()
	{

		SettlementName = SettlementNameText.text;
	
	}
	
	//---------------------------------------------------------------------------------------------
	void Update () {
		
	}
	
	//---------------------------------------------------------------------------------------------
	// Core Functions 
	
	//---------------------------------------------------------------------------------------------
	public void SetName()
	{
		CurrentSettlement = PlayerPrefs.GetInt("ActiveSettlement");
		Destination = Settlement_ID;
		obj_CurrentSettlement = SettlementMain.Settlements[CurrentSettlement];
		obj_DestinationSettlement = SettlementMain.Settlements[Destination];
		
		distance = Vector3.Distance(obj_CurrentSettlement.transform.position,obj_DestinationSettlement.transform.position);  
		float setdistance = Mathf.Floor(distance)/2;
		PopupDistance.text = setdistance + " KM";
		GoButton.Destination = Settlement_ID;
		GoButton.distance = TempDistance;
		PopupText.text = SettlementName;
	
	}

	//---------------------------------------------------------------------------------------------
	
	
	//---------------------------------------------------------------------------------------------
	public void CheckConnection()
	{
		gameObject.GetComponent<Button>().image.color = Color.yellow;
		for (int a = 0; a < ConnectedTowns.Count; a++)
		{
			Button Tested = ConnectedTowns[a].GetComponent<Button>();
			Tested.image.color = Color.white;
			Tested.interactable = true;
	
		}
	}

	
}
